package com.classes;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.TreeMap;

import com.mbbmap.app.manager.ConfigManager;
import com.mbbmap.app.manager.DBConnectionManager;

public class CaseOutlet {
	private long case_id = 0;
	private String outlet_details = "";
	private String esa_ref_no = "";
	private String num_terminal = "";
	private String trm_rental = "";
	private String trm_owner = "";
	private String trm_deposit_wired = "";
	private String trm_deposit_wireless = "";
	private String trm_rental_deposit_wired = "";
	private String trm_rental_deposit_wireless = "";
	private String trm_rental_advance = "";
	private String cheque_amt = "";
	private String cheque_issuer = "";
	private String cheque_no = "";
	private String cheque_date = "";
	private String terminal_id = "";
	private String terminal_id_no = "";
	private String terminal_install_date = "";
	private Outlet outlet; 
	private String recommendation = "";
	private String pos_form = "";
	private String pos_installation = "";
	private String mid_pos = "";
	private String mid_amex = "";
	private ArrayList<TreeMap<String, String>> install_notes;
	
	public long getCaseId() {
		return this.case_id;
	}
	
	public String getOutletDtl() {
		return this.outlet_details;
	}
	
	public String getESARefNo() {
		return this.esa_ref_no;
	}
	
	public String getNumTerminal() {
		return this.num_terminal;
	}
	
	public String getTrmRental() {
		return this.trm_rental;
	}
	
	public String getTrmOwner() {
		return this.trm_owner;
	}
	
	public String getTrmDepositWired() {
		return this.trm_deposit_wired;
	}
	
	public String getTrmDepositWireless() {
		return this.trm_deposit_wireless;
	}
	
	public String getTrmRentalDepositWired() {
		return this.trm_rental_deposit_wired;
	}
	
	public String getTrmRentalDepositWireless() {
		return this.trm_rental_deposit_wireless;
	}
	
	public String getTrmRentalAdvance() {
		return this.trm_rental_advance;
	}
	
	public String getChequeAmt() {
		return this.cheque_amt;
	}
	
	public String getChequeIssuer() {
		return this.cheque_issuer;
	}
	
	public String getChequeNo() {
		return this.cheque_no;
	}
	
	public String getChequeDate() {
		return this.cheque_date;
	}
	
	public String getTerminalID() {
		return this.terminal_id;
	}
	
	public String getTerminalIDNo() {
		return this.terminal_id_no;
	}
	
	public String getTerminalInstallDate() {
		return this.terminal_install_date;
	}
	
	public Outlet getOutlet() {
		return this.outlet;
	}
	
	public String getRecommendation() {
		return this.recommendation;
	}
	
	public String getPosForm() {
		return this.pos_form;
	}
	
	public String getPosInstallation() {
		return this.pos_installation;
	}
	
	public String getMidPOS() {
		return this.mid_pos;
	}
	
	public String getMidAMEX() {
		return this.mid_amex;
	}
	
	public ArrayList<TreeMap<String, String>> getInstallNotes(){
		return this.install_notes;
	}
	
	public void setCaseId(long v) {
		this.case_id = v;
	}
	
	public void setOutletDtl(String value) {
		if(value != null)
			this.outlet_details = value;
	}
	
	public void setESARefNo(String value) {
		if(value != null)
			this.esa_ref_no = value;
	}
	
	public void setNumTerminal(String value) {
		if(value != null)
			this.num_terminal = value;
	}
	
	public void setTrmRental(String value) {
		if(value != null)
			this.trm_rental = value;
	}
	
	public void setTrmOwner(String value) {
		if(value != null)
			this.trm_owner = value;
	}
	
	public void setTrmDepositWired(String value) {
		if(value != null)
			this.trm_deposit_wired = value;
	}
	
	public void setTrmDepositWireless(String value) {
		if(value != null)
			this.trm_deposit_wireless = value;
	}
	
	public void setTrmRentalDepositWired(String value) {
		if(value != null)
			this.trm_rental_deposit_wired = value;
	}
	
	public void setTrmRentalDepositWireless(String value) {
		if(value != null)
			this.trm_rental_deposit_wireless = value;
	}
	
	public void setTrmRentalAdvance(String value) {
		if(value != null)
			this.trm_rental_advance = value;
	}
	
	public void setChequeAmt(String value) {
		if(value != null)
			this.cheque_amt = value;
	}
	
	public void setChequeIssuer(String value) {
		if(value != null)
			this.cheque_issuer = value;
	}
	
	public void setChequeNo(String value) {
		if(value != null)
			this.cheque_no = value;
	}
	
	public void setChequeDate(String value) {
		if(value != null)
			this.cheque_date = value;
	}
	
	public void setTerminalID(String value) {
		if(value != null)
			this.terminal_id = value;
	}
	
	public void setTerminalIDNo(String value) {
		if(value != null)
			this.terminal_id_no = value;
	}
	
	public void setTerminalInstallDate(String value) {
		if(value != null)
			this.terminal_install_date = value;
	}
	
	public void setOutlet(Outlet value) {
		this.outlet = value;
	}
	
	public void setRecommendation(String value) {
		if(value != null)
			this.recommendation = value;
	}
	
	public void setPosForm(String value) {
		if(value != null)
			this.pos_form = value;
	}
	
	public void setPosInstallation(String value) {
		if(value != null)
			this.pos_installation = value;
	}
	
	public void setMidPOS(String value) {
		if(value != null)
			this.mid_pos = value;
	}
	
	public void setMidAMEX(String value) {
		if(value != null)
			this.mid_amex = value;
	}
	
	public void loadInstallNotes(String vendor_name){
		
        String connectionPool = ConfigManager.getInstance().getConnectionPool();
        DBConnectionManager connMgr = DBConnectionManager.getInstance();
        Connection conn = connMgr.getConnection(connectionPool, 10000);
        
		try{
			String sql = "select * from caseinstallnote where in_case_id = ? and in_outlet_id = ? and in_vendor_name = ? order by 1 asc";
			
			PreparedStatement statement = conn.prepareStatement(sql);
			
			try {
				statement.setLong(1, this.case_id);
				statement.setLong(2, this.getOutlet().getId());
				statement.setString(3, vendor_name);
				
				ResultSet resultSet = statement.executeQuery();
				
				this.install_notes = new ArrayList<TreeMap<String, String>>();
				
				try {
					while(resultSet.next()){
						TreeMap<String, String> histLog = new TreeMap<String, String>();
						histLog.put("id", resultSet.getString("in_id"));
						histLog.put("status", resultSet.getString("in_status"));
						
						String temp = resultSet.getString("in_remark");
						if(resultSet.wasNull()){
							temp = "";
						}
						
						histLog.put("note", temp);
						
						histLog.put("created_by", resultSet.getString("in_created_by"));
						histLog.put("created_date", Long.toString(((Timestamp) resultSet.getTimestamp("in_created_date")).getTime()));
						
						this.install_notes.add(histLog);
					}
				} finally {
					resultSet.close();
				}
			} finally {
				statement.close();
			}
			
		} catch(Exception e){
			e.printStackTrace();
		} finally {
			connMgr.freeConnection(connectionPool, conn);
		}
	}
}
